package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.string.StringUtils;
import com.letv.whatslive.common.utils.StringUtil;
import com.letv.whatslive.model.UserIdentityAuditAllow;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2016/10/10.
 */
public class UserIdentityAuditAllowConvert {
    public static DBObject castUserIdentityAuditAllowToDBObject(UserIdentityAuditAllow userIdentityAuditAllow){
        DBObject dbo = new BasicDBObject();
        if(userIdentityAuditAllow.getId()!=null){
            dbo.put("_id",userIdentityAuditAllow.getId());
        }

        if(userIdentityAuditAllow.getUserId()!=null){
            dbo.put("userId",ObjUtils.toLong(userIdentityAuditAllow.getUserId()));
        }
        if(!StringUtils.isBlank(userIdentityAuditAllow.getNickName())){
            dbo.put("nickName",ObjUtils.toString(userIdentityAuditAllow.getNickName()));
        }
        dbo.put("createTime",ObjUtils.toLong(userIdentityAuditAllow.getCreateTime(), System.currentTimeMillis()));
        return dbo;
    }

    public static UserIdentityAuditAllow castDBObjectToUserIdentityAuditAllow(DBObject dbObject){
        UserIdentityAuditAllow userIdentityAuditAllow = new UserIdentityAuditAllow();
        if(dbObject != null) {
            userIdentityAuditAllow.setId(ObjUtils.toLong(dbObject.get("_id")));
            if(dbObject.get("userId")!=null)
                userIdentityAuditAllow.setUserId(ObjUtils.toLong(dbObject.get("userId")));
            if(dbObject.get("nickName")!=null)
                userIdentityAuditAllow.setNickName(ObjUtils.toString(dbObject.get("nickName")));
            userIdentityAuditAllow.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
        }

        return userIdentityAuditAllow;
    }
}
